<template>
  <div class="model-container">
    <div class="listName">分润管理</div>
    <!--搜索-->
    <el-card shadow="never">
      <div slot="header" class="clearfix">
        <span>快捷搜索</span>
        <div class="btns-wrapper-right">
          <el-button v-if="!searchShow" icon="el-icon-arrow-down" @click="searchShow = true" />
          <el-button v-else icon="el-icon-arrow-up" @click="searchShow = false" />
        </div>
      </div>
      <el-collapse-transition>
        <div v-show="searchShow" class="cardbody">
          <el-form ref="seacherParam" :model="seacherParam">
            <el-row :gutter="10">
              <el-col :xl="5" :lg="6" :md="6" :sm="8">
                <el-col :xl="7" :lg="7" :md="8" :sm="8" class="input-name">店铺名称</el-col>
                <el-col :xl="17" :lg="17" :md="16" :sm="16">
                  <el-form-item prop="sellerName">
                    <el-input v-model="seacherParam.sellerName" size="small" placeholder="请输入店铺名称" />
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :xl="5" :lg="6" :md="6" :sm="8">
                <el-col :xl="7" :lg="7" :md="8" :sm="8" class="input-name">审核状态</el-col>
                <el-col :xl="17" :lg="17" :md="16" :sm="16">
                  <el-form-item prop="censorStatus">
                    <el-select v-model="seacherParam.censorStatus" placeholder="请选择" size="small">
                      <el-option :value="-1" label="全部" />
                      <el-option :value="0" label="待审核" />
                      <el-option :value="1" label="已审核" />
                      <el-option :value="2" label="审核不通过但可重新提交申请" />
                      <el-option :value="3" label="终审不通过不能再申请" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
            </el-row>
            <div class="cardfooter">
              <el-button type="primary" size="mini" plain @click="seachFun">查询</el-button>
              <el-button type="warning" size="mini" plain @click="resetFun">重置</el-button>
            </div>
          </el-form>
        </div>
      </el-collapse-transition>
    </el-card>
    <!--表格-->
    <el-card style="margin-top: 10px">
      <div class="table-wrapper">
        <el-table v-loading="!dataOption" :stripe="true" :data="dataOption" border empty-text="暂无数据" @selection-change="changeFun">

          <el-table-column align="center" width="55" label="序号" type="index" />

          <el-table-column align="center" prop="sellerName" label="商家名称" />

          <el-table-column align="center" prop="address" label="商家地址" />

          <el-table-column align="center" prop="sellerId" label="商家ID" />

          <el-table-column align="center" label="视频评论">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.videoAllow"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="changeVideo(scope.row)" />
            </template>
          </el-table-column>

          <el-table-column align="center" label="资讯评论">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.newsAllow"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="changeInformation(scope.row)" />
            </template>
          </el-table-column>

          <el-table-column align="center" label="商品评论">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.itemAllow"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="changeCommodity(scope.row)" />
            </template>
          </el-table-column>

          <el-table-column align="center" label="全部">
            <template slot-scope="scope">
              <el-switch
                v-model="allAllow"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="changeAll(scope.row)" />
            </template>
          </el-table-column>
        </el-table>

        <!--分页-->
        <el-pagination
          :current-page="pageNo"
          :page-sizes="[10, 20, 30]"
          :page-size="pageSize"
          :total="rowCount"
          background
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </el-card>

  </div>
</template>

<script>
import * as comment from '../../api/comment.js'
export default {
  components: {},
  data() {
    return {
      videoAllow: 0,
      allAllow: 0,

      isRouterAlive: true,
      // 输入禁用
      disableIinput: false,
      // 省市区
      provinceList: null,
      cityList: null,
      areaList: null,
      // 页面搜索
      seacherParam: {
        sellerName: '',
        censorStatus: -1
      },
      searchShow: false,
      pageNo: 1,
      pageSize: 10,
      rowCount: null, // 总条数
      // 弹框
      dialogType: 1, // 1--增加  2--编辑  3--审核   4--重新审核
      dialogState: false,
      // 按钮状态
      buttonState: false,
      // 列表数据
      dataOption: null,
      // 提交内容
      disabled: false,
      datavalID: [],
      dialogBindData: {

      },
      rules: {

      }
    }
  },
  beforeMount() {
    this.getList()
  },
  methods: {
    seachFun() {
      const param = {
        current: 1,
        size: this.pageSize,
        sellerName: this.seacherParam.sellerName
      }
      comment.getSellerSub(param).then(res => {
        console.log('评论管理列表的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始话表格数据
        this.dataOption = res.data.data.records
        // 初始化分页数据
        this.rowCount = res.data.data.total
        this.pageSize = res.data.data.size
      })
    },

    // 是否可以视频评论
    changeVideo(data) {
      console.log('数据', data.videoAllow)
      const param = {
        sellerId: data.sellerId,
        videoAllow: data.videoAllow === 1 ? 0 : 1
      }
      console.log(param.videoAllow)
      comment.updateSellerSub(param).then(res => {
        console.log('修改的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
      })
    },

    // 是否可以资讯评论
    changeInformation(data) {
      const param = {
        sellerId: data.sellerId,
        newsAllow: data.newsAllow === 1 ? 0 : 1
      }
      comment.updateSellerSub(param).then(res => {
        console.log('修改的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
      })
    },

    // 是否可以商品评论
    changeCommodity(data) {
      const param = {
        sellerId: data.sellerId,
        itemAllow: data.itemAllow === 1 ? 0 : 1
      }
      comment.updateSellerSub(param).then(res => {
        console.log('修改的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
      })
    },

    // 是否可以全部
    changeAll(data) {
      const param = {
        sellerId: data.sellerId,
        videoAllow: data.videoAllow === 1 ? 0 : 1,
        newsAllow: data.newsAllow === 1 ? 0 : 1,
        itemAllow: data.itemAllow === 1 ? 0 : 1
      }
      comment.updateSellerSub(param).then(res => {
        console.log('修改的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
      })
    },

    // 重置
    resetFun() {
      this.$refs.seacherParam.resetFields()
      this.pageNo = 1
      this.pageSize = 10
      this.getList()
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNo = val
      this.getList()
    },
    handleClose() {
      for (const key in this.dialogBindData) {
        if (key === 'sellerType') {
          this.dialogBindData[key] = 1
        } else if (key === 'settlementPeriod') {
          this.dialogBindData[key] = 1
        } else {
          this.dialogBindData[key] = ''
        }
      }
      this.dialogState = false
      this.disabled = false
      this.disableIinput = false
      this.isRouterAlive = false
      this.$refs.dialogBindData.clearValidate()
    },

    getList() {
      const param = {
        current: this.pageNo,
        size: this.pageSize
      }
      comment.getSellerSub(param).then(res => {
        console.log('评论管理列表的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始话表格数据
        this.dataOption = res.data.data.records
        // 初始化分页数据
        this.rowCount = res.data.data.total
        this.pageSize = res.data.data.size
      })
    },

    // 编辑
    edit(data) {
      this.$router.push({
        name: '/v1/merchant_add',
        params: {
          data: data,
          dialogType: 2
        }
      })
    },
    // 提交
    submmitFun() {

    },
    // 删除
    changeFun(data) {
      this.datavalID = data
    }

  }
}

</script>
<style type="text/scss" lang="scss">
	.formBody {
    .el-dialog__body{
      padding: 10px;
    }
  }
</style>
<style type="text/scss" lang="scss" scoped>
	.formBody{
    height: 600px;
    overflow: auto;
  }
  .statusClass{
    cursor: pointer;
    color: #33CC00;
  }
  .statusClassnew{
    cursor: pointer;
    color: #FF0033;
  }
</style>
